project(cman)
cmake_minimum_required(VERSION 3.22)

# disable cmake warning regarding too new (and threfore unsupported) version of boost
set(Boost_NO_WARN_NEW_VERSIONS 1)
find_package(Boost)

set(CFLAGS_SEC "-Wl,-z,-relro,-z,now,-z,noexecstack -fvisibility=hidden -fstack-protector-strong \
    -ftrapv -D_FORTIFY_SOURCE=2 -O2 -s")
set(CFLAGS_COV "-fprofile-arcs -ftest-coverage -lgcov")
set(CFLAGS_ASAN "-fsanitize=leak -fno-stack-protector -fno-omit-frame-pointer \
    -fsanitize=address -fsanitize-recover=address,all")
set(CMAN_COMPILE_OPTIONS -Wall -Wno-error -Wno-error=format -Wuninitialized
    -Wundef -Wunused -Wdate-time -Wshadow -Wvla -Wdisabled-optimization
    -Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough=3
    -Wtype-limits -Wshift-negative-value -Wframe-larger-than=8192
    -Wshift-overflow=2 -Wwrite-strings -Wmissing-format-attribute
    -Wformat-nonliteral -Wduplicated-cond -Wtrampolines -Wlogical-op
    -Wsuggest-attribute=format -Wduplicated-branches -Wmissing-include-dirs
    -Wformat-signedness -Wmissing-declarations -Wreturn-local-addr -Wredundant-decls
    -Wmissing-prototypes -Wstrict-prototypes)

option(ENABLE_COV "Enable code coverage" OFF)
option(ENABLE_ASAN "Enable Address Sterilization" OFF)

if(ENABLE_ASAN)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CFLAGS_ASAN}")
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS_ASAN}")
elseif(ENABLE_COV)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CFLAGS_COV}")
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS_COV}")
else()
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CFLAGS_SEC}")
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS_SEC}")
endif()

add_subdirectory(drv)
add_subdirectory(uapi)